userManagementProto = {
   userEditorGrid : null
   ,userEditorStore : null
   ,initComponent: function(){
       this.items = [this.contentItems];

       userManagement.superclass.initComponent.call(this);
 
       this.userEditorStore = this.userEditorGrid.getStore();

       this.initHandlers();
       this.initListeners();
       this.reloadGrid();
   }
   , initHandlers : function()
    {
        sweatShop.globals.bindHandlers(this.id, {
          deleteUserButton : {item: this.deleteUserButton, fn: this.onDelete, scope: this}
          ,addUserButton : {item: this.addUserButton, fn: this.addUser, scope: this}
          ,saveButton : {item: this.userEditorGrid.saveButton, fn: this.onSave, scope: this}
          ,reloadButton : {item: this.reloadButton, fn: this.reloadGrid, scope: this}
        });
    }
    ,initListeners : function()
    {
        sweatShop.globals.bindListeners(this.id, {
          storeWrite : {item: this.userEditorStore, event: 'write', fn: this.resultListener, scope: this}
          //,storeDelete : {item: this.userEditorStore, event: 'remove', fn: this.resultListener, scope: this}
        });
    }
    , reloadGrid : function ()
    {
        sweatShop.log('test', 0);
        this.userEditorStore.reload();
    }
    , onSave : function(btn, ev) {
        this.userEditorStore.save();
    }
    , onDelete : function (btn, ev)
    {
        Ext.MessageBox.confirm('Remove user'
            , 'Youre about to remove a user, pleace confirm.<br/>This action cannot be undone'
            , this.removeUser
            , this);
    }
    , removeUser : function(btn)
    {
        if(btn == 'yes')
        {
            var index = this.userEditorGrid.getSelectionModel().getSelectedCell();
            if (!index) {
                return false;
            }
            var rec = this.userEditorStore.getAt(index[0]);
           this.userEditorStore.remove(rec);
           this.userEditorStore.save();
        }
    }
    , afterDelete : function(a,b,c,d)
    {
        console.log(a,b,c,d);
    }
    , addUser : function()
    {
        
        this.userEditorGrid.stopEditing();
        globals.createEmptyRecordToGrid(this.userEditorGrid,{
             username : ''
            , email : ''
            , userGroupId : 1
            , userStatusId : 1
            , password1 : ''
            , password2 : ''
        });
        //globals.createEmptyRecordToGrid(this.userEditorGrid);
        this.userEditorGrid.startEditing(0,1);
    }
    , newUserWizard : function()
    {
        new newUserWizard().show();
    }
    , resultListener : function(DataProxy, action, data, response)
    {
       sweatShop.log(response.raw.message, response.raw.success ? 1 : 3);
    }
};
userManagement = Ext.extend(userManagementUi, userManagementProto);